/**
 * ScaleFactory - Creates correct scale based on input configuration file.
 * CS575 Software Design
 * Group 6
 * Group Members: Anthony Davidson, Kendra Scheesley, Lyndsey Whitman, Stephen Zakrewsky
 * Date: May 19, 2012
 * Main Author(s): Kendra Scheesley
 * 
 * Modified: 6/1 Stephen Zakrewsky
 * Modified: 6/2 Kendra Scheesley
 */

package edu.drexel.cs575.a3;

public class ScaleFactory
{
	private static ScaleFactory instance = null;
	
	private PowerUnitFactory powerUnitFactory;
	private DisplayFactory displayFactory;
	private BillFactory billFactory;
	
	private ScaleFactory()
	{
		this.powerUnitFactory = new PowerUnitFactory();
		this.displayFactory   = new DisplayFactory();
		this.billFactory = new BillFactory();
	}
	
	public static synchronized ScaleFactory getInstance()
	{
		if (instance == null)
		{
			instance = new ScaleFactory();
		}
		
		return instance;
	}
	
	public Scale createScale(int modelNumber)
	{
		Scale newScale = new Scale();
		ScaleConfigCollector scaleModel = new ScaleConfigCollector(modelNumber);
		
		//call displayFactory to set appropriate display based on config file value
		newScale.setDisplay(createDisplay(scaleModel.getDisplay()));
		
		//call powerUnitFactory to set appropriate power unit based on config file value
		newScale.setPowerUnit(createPowerUnit(scaleModel.getPowerUnit()));
		
		//call billFactory to set appropriate display based on config file value
		newScale.setBill(createBill(scaleModel.getBill()));
		
		//set the default output to the display
		newScale.setOutput(newScale.getDisplay());
		
		//set the weighing mechanism
		newScale.setWeighingMechanism(new WeighingMechanism());
		
		return newScale;
	}
	
	private PowerUnit createPowerUnit(String type)
	{
		return powerUnitFactory.createPowerUnit(type);
	}
	
	private Display createDisplay(String type)
	{
		
		return displayFactory.createDisplay(type);	
	}
	
	private Bill createBill(String type)
	{
		
		return billFactory.createBill(type);	
	}
	
}
